Bounds checking may be done in computer programs to detect whether a variable is within some specified bounds. For example, a value may be checked before it is used as an index into an array to determine whether the value lies within the bounds of the array; this kind of bounds checking is sometimes called index checking or range checking. A failed bounds check may generate a runtime error, such as an exception signal. An attempt to access an array or other variable outside its bounds often indicates a programming error. However, performing a bounds check before every use of a bounded variable is not always done, because bounds checks increase program execution time.
Compilers sometimes automatically eliminate bounds checks that are deemed unnecessary. As an example, consider program code that reads a value from a location within an array and then stores another value (or the same value) back into that same location. Without any optimization, this code might include a first bounds check when the array location is read from the array and a second bounds check when the same location in the array is written. But a compiler or other optimizing tool may automatically eliminate the second bounds check after determining that the array size is unchanged and that the same location in the array is being read and then written. More generally, a variety of optimizations are used in compilers and other tools to automatically reduce or eliminate redundant bounds checks.